import model from '../../models/request'

export const initimg = () => (dispatch) => {
   model.getSwiperData()
      .then(res => {
         //  console.log(res)
         dispatch({
            type: 'addimg',
            data: res.data.data

         })
      })
}
// 请求热门分类
export const hotlist = () => (dispatch) => {
   model.getHotlistData()
      .then(res => {
         // console.log(res)
         dispatch({
            type: 'addhotlist',
            data: res.data

         })
      })
}
// 发送分类数据
export const category = () => (dispatch) => {
   model.getcategoryData()
      .then(res => {
         var arr = res.data.data.category
         let result = []
         for (let key in arr) {
            let obj = {
               name: key,
               data: arr[key]
            }
            result.push(obj)
         }
         dispatch({
            type: 'category',
            data:  result
         })
      })



}
// 发送食材数据
export const material = () => (dispatch) => {
   model.getcategoryData()
      .then(res => {
         var arr = res.data.data.material
         let result = []
         for (let key in arr) {
            let obj = {
               name: key,
               data: arr[key]
            }
            result.push(obj)
         }
         dispatch({
            type: 'material',
            data:  result
         })
      })



}